<?php

/**
 * 应收款项条目仓库
 * @author wangwx 2015-5-12
 */
namespace common\repositories\myhtsq;
use common\repositories\BaseRepository;
use common\support\StringHelper;
use common\entities\myhtsq\ReceivableItemEntity;
class ReceivableItemRepository extends BaseRepository{
	/**
	 * 构造方法
	 * @param unknown $config (optional)
	 */
	public function __construct($config = [])
	{
		parent::__construct($config);
	}
	
	/**
	 * 根据关键字，获取产品名称列表
	 * @param string $keyword 关键字
	 * @param string $keyword 关键字
	 * @return array
	 */
	public static function getReceivableItemByKeyword($keyword,$limit=10) {
		
		$query = ReceivableItemEntity::find();
		if (!empty($keyword)) {
			$query->where(['like', 'receivable_item_name', $keyword]);
		}
		return $query->limit($limit)->all();
	}
	
	/**
	 * 根据款项id,获取款项名称
	 * @param string $receivableItemId 款项id
	 * @return string 款项名称
	 */
	public static function getReceivableItemNameByItemId($receivableItemId){
		$str = ReceivableItemEntity::find()->select('receivable_item_name')->where(['receivable_item_id'=>$receivableItemId])->scalar();
		if (empty($str)) {
			$str = '';
		}
		return $str;
	}

	/**
	 * 根据id,获取名称
	 * @param string $receivableItemName 款项名称
	 * @return string 款项名称
	 */
	public static function getReceivableItemIdByItemName($receivableItemName)
	{
		$str = ReceivableItemEntity::find()->select('receivable_item_id')->where(['receivable_item_name' => $receivableItemName])->scalar();
		if (empty($str)) {
			$str = '';
		}
		return $str;
	}


}